]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
messageTray: Allow settings gobject properties of Source on creation
authorJulian Sparber <julian@sparber.net>
Thu, 25 Jan 2024 20:52:34 +0000 (21:52 +0100)
committerMarge Bot <marge-bot@gnome.org>
Tue, 30 Jan 2024 17:05:23 +0000 (17:05 +0000)
This also makes the `icon` property of `Source` writable so that it can
be set during creation instead of overriding the getter of the icon
property.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3103>

js/ui/components/autorunManager.js
js/ui/components/networkAgent.js
js/ui/components/telepathyClient.js
js/ui/extensionSystem.js
js/ui/messageTray.js
js/ui/notificationDaemon.js
js/ui/screenshot.js
js/ui/shellMountOperation.js
js/ui/status/network.js
js/ui/status/thunderbolt.js
js/ui/windowAttentionHandler.js

index 9570b121909a5a91e9f295a66f6fed116199bc2b..1ca58510f0cc82277c828b39e98931c513b764bd 100644 (file)
@@ -258,8 +258,11 @@ class AutorunDispatcher {
 
 const AutorunSource = GObject.registerClass(
 class AutorunSource extends MessageTray.Source {
-    _init(manager, mount, apps) {
-        super._init(mount.get_name());
+    constructor(manager, mount, apps) {
+        super({
+            title: mount.get_name(),
+            icon: mount.get_icon(),
+        });
 
         this._manager = manager;
         this.mount = mount;
@@ -272,10 +275,6 @@ class AutorunSource extends MessageTray.Source {
         this.showNotification(this._notification);
     }
 
-    get icon() {
-        return this.mount.get_icon();
-    }
-
     _createPolicy() {
         return new MessageTray.NotificationApplicationPolicy('org.gnome.Nautilus');
     }
index 3d187a87897eb1c2cc62d76c92f4137641304243..2a31b3037f978d523bbce78e5d70c57bfc3bdf90 100644 (file)
@@ -740,7 +740,10 @@ class NetworkAgent {
     }
 
     _showNotification(requestId, connection, settingName, hints, flags) {
-        let source = new MessageTray.Source(_('Network Manager'), 'network-transmit-receive');
+        const source = new MessageTray.Source({
+            title: _('Network Manager'),
+            iconName: 'network-transmit-receive',
+        });
         source.policy = new MessageTray.NotificationApplicationPolicy('gnome-network-panel');
 
         let title, body;
index 5a5aec359efbbf665d9fc341b37d9570be710425..04d6f3af794cc32fa5d29c38466f709dffa411d4 100644 (file)
@@ -312,7 +312,7 @@ class ChatSource extends MessageTray.Source {
         this._contact = contact;
         this._client = client;
 
-        super._init(contact.get_alias());
+        super._init();
 
         this._pendingMessages = [];
 
@@ -333,6 +333,8 @@ class ChatSource extends MessageTray.Source {
             'notify::alias', this._updateAlias.bind(this),
             'notify::avatar-file', this._updateAvatarIcon.bind(this), this);
 
+        this._updateAlias();
+        this._updateAvatarIcon();
         // Add ourselves as a source.
         Main.messageTray.add(this);
 
@@ -378,22 +380,23 @@ class ChatSource extends MessageTray.Source {
         if (oldAlias === newAlias)
             return;
 
-        this.setTitle(newAlias);
+        this.title = newAlias;
         if (this._notification)
             this._notification.appendAliasChange(oldAlias, newAlias);
     }
 
-    get icon() {
+    _updateAvatarIcon() {
         let file = this._contact.get_avatar_file();
-        if (file)
-            return new Gio.FileIcon({file});
-        else
-            return new Gio.ThemedIcon({name: 'avatar-default'});
-    }
+        if (file) {
+            if (this.icon instanceof Gio.FileIcon)
+                this.icon.file = file;
+            else
+                this.icon = new Gio.FileIcon({file});
+        } else if (!(this.icon instanceof Gio.ThemedIcon)) {
+            this.iconName = 'avatar-default';
+        }
 
-    _updateAvatarIcon() {
-        this.notify('icon');
-        if (this._notification) {
+        if (this._notification && this.icon !== this._notification.gicon) {
             this._notification.update(
                 this._notification.title,
                 this._notification.bannerBodyText,
index 356c43b2d67b75ef128c8988882db783e7bcd94b..b3e43b13971a43f5b0e40ce0051ddef349671bad 100644 (file)
@@ -830,11 +830,10 @@ class ExtensionUpdateSource extends MessageTray.Source {
         if (!this._app)
             this._app = appSys.lookup_app('com.mattjakeman.ExtensionManager.desktop');
 
-        super._init(this._app.get_name());
-    }
-
-    get icon() {
-        return this._app.app_info.get_icon();
+        super._init({
+            title: this._app.get_name(),
+            icon: this._app.get_icon(),
+        });
     }
 
     _createPolicy() {
index 7acccc9c43d773147a2964039e477462df90e9e3..bd8be9b29c81a9cfb6bb1e07e4f98aa42827e128 100644 (file)
@@ -609,10 +609,8 @@ export const Source = GObject.registerClass({
         'notification-show': {param_types: [Notification.$gtype]},
     },
 }, class Source extends GObject.Object {
-    _init(title, iconName) {
-        super._init({title});
-
-        this.icon = new Gio.ThemedIcon({name: iconName});
+    constructor(params) {
+        super(params);
 
         this.notifications = [];
 
@@ -655,14 +653,6 @@ export const Source = GObject.registerClass({
             : PrivacyScope.USER;
     }
 
-    setTitle(newTitle) {
-        if (this.title === newTitle)
-            return;
-
-        this.title = newTitle;
-        this.notify('title');
-    }
-
     createBanner(notification) {
         return new NotificationBanner(notification);
     }
@@ -1349,8 +1339,11 @@ export const MessageTray = GObject.registerClass({
 
 export const SystemNotificationSource = GObject.registerClass(
 class SystemNotificationSource extends Source {
-    _init() {
-        super._init(_('System Information'), 'dialog-information-symbolic');
+    constructor() {
+        super({
+            title: _('System Information'),
+            iconName: 'dialog-information-symbolic',
+        });
     }
 
     open() {
index 23d44458c1375016419787958dd419cb3887d3d6..cec670dd09e877a4ee9b898511b482360358abfc 100644 (file)
@@ -309,10 +309,13 @@ class FdoNotificationDaemonSource extends MessageTray.Source {
         this.pid = pid;
         this.initialTitle = title;
         this.app = this._getApp(appId);
+        this._appIcon = null;
 
         // Use app name as title if available, instead of whatever is provided
         // through libnotify (usually garbage)
-        super._init(this.app ? this.app.get_name() : title);
+        super._init({
+            title: this.app?.get_name() ?? title,
+        });
 
         if (sender) {
             this._nameWatcherId = Gio.DBus.session.watch_name(sender,
@@ -349,6 +352,7 @@ class FdoNotificationDaemonSource extends MessageTray.Source {
             this.notify('icon');
         }
 
+
         let tracker = Shell.WindowTracker.get_default();
         if (notification.resident && this.app && tracker.focus_app === this.app)
             this.pushNotification(notification);
@@ -397,12 +401,7 @@ class FdoNotificationDaemonSource extends MessageTray.Source {
     }
 
     get icon() {
-        if (this.app)
-            return this.app.get_icon();
-        else if (this._appIcon)
-            return this._appIcon;
-        else
-            return null;
+        return this.app?.get_icon() ?? this._appIcon;
     }
 });
 
@@ -519,16 +518,15 @@ class GtkNotificationDaemonAppSource extends MessageTray.Source {
         this._app = app;
         this._objectPath = objectPath;
 
-        super._init(app.get_name());
+        super._init({
+            title: app.get_name(),
+            icon: app.get_icon(),
+        });
 
         this._notifications = {};
         this._notificationPending = false;
     }
 
-    get icon() {
-        return this._app.get_icon();
-    }
-
     _createPolicy() {
         return new MessageTray.NotificationApplicationPolicy(this._appId);
     }
index 464e9567293aa303fcc1b9a006d5736eaeb7885d..e5b50604db0c27f5d155fdda130cc1da42e7d932 100644 (file)
@@ -2025,11 +2025,11 @@ export const ScreenshotUI = GObject.registerClass({
         // Show a notification.
         const file = Gio.file_new_for_path(this._screencastPath);
 
-        const source = new MessageTray.Source(
+        const source = new MessageTray.Source({
             // Translators: notification source name.
-            _('Screenshot'),
-            'screencast-recorded-symbolic'
-        );
+            title: _('Screenshot'),
+            iconName: 'screencast-recorded-symbolic',
+        });
         const notification = new MessageTray.Notification(
             source,
             title,
@@ -2262,11 +2262,11 @@ function _storeScreenshot(bytes, pixbuf) {
     );
 
     // Show a notification.
-    const source = new MessageTray.Source(
+    const source = new MessageTray.Source({
         // Translators: notification source name.
-        _('Screenshot'),
-        'screenshot-recorded-symbolic'
-    );
+        title: _('Screenshot'),
+        iconName: 'screenshot-recorded-symbolic',
+    });
     const notification = new MessageTray.Notification(
         source,
         // Translators: notification title.
index caef313af276db17e623fbf846107ffc41ef2ba4..d2ab867583902ef22a6c471a30fe776cdb2bf405 100644 (file)
@@ -198,8 +198,10 @@ export class ShellMountOperation {
 
 const ShellUnmountNotifier = GObject.registerClass(
 class ShellUnmountNotifier extends MessageTray.Source {
-    _init() {
-        super._init('', 'media-removable');
+    constructor() {
+        super({
+            iconName: 'media-removable',
+        });
 
         this._notification = null;
         Main.messageTray.add(this);
index d9547eed73966e7b63975fdbbe7814a919838798..4322c6761b8d77548b2bcec03897d7a255a9ec47 100644 (file)
@@ -2036,8 +2036,10 @@ class Indicator extends SystemIndicator {
     _onActivationFailed() {
         this._notification?.destroy();
 
-        const source = new MessageTray.Source(
-            _('Network Manager'), 'network-error-symbolic');
+        const source = new MessageTray.Source({
+            title: _('Network Manager'),
+            iconName: 'network-error-symbolic',
+        });
         source.policy =
             new MessageTray.NotificationApplicationPolicy('gnome-network-panel');
 
index 0005339d0f5e1e3c3705a208bfa8d5e1a439b2c2..51b6e4ba659ea56fbc0fbca856197aae6561b89e 100644 (file)
@@ -256,8 +256,10 @@ class Indicator extends SystemIndicator {
 
     _ensureSource() {
         if (!this._source) {
-            this._source = new MessageTray.Source(_('Thunderbolt'),
-                'thunderbolt-symbolic');
+            this._source = new MessageTray.Source({
+                title: _('Thunderbolt'),
+                iconName: 'thunderbolt-symbolic',
+            });
             this._source.connect('destroy', () => (this._source = null));
 
             Main.messageTray.add(this._source);
index 8ba38685e7b807e31e941474b1e3976a4558c920..dfce5c1b9b1bdb545711260f99393f45fc122b39 100644 (file)
@@ -60,7 +60,10 @@ class WindowAttentionSource extends MessageTray.Source {
         this._window = window;
         this._app = app;
 
-        super._init(app.get_name());
+        super._init({
+            title: this._app.get_name(),
+            icon: this._app.get_icon(),
+        });
 
         this._window.connectObject(
             'notify::demands-attention', this._sync.bind(this),
@@ -84,10 +87,6 @@ class WindowAttentionSource extends MessageTray.Source {
         }
     }
 
-    get icon() {
-        return this._app.get_icon();
-    }
-
     destroy(params) {
         this._window.disconnectObject(this);